package com.im.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.im.MDA;
import com.im.service.common.dao.IFileQueryDAO;
import com.im.service.dto.BaseException;
import com.im.service.dto.BusiConstParamVal;
import com.im.service.dto.DocInfo;
import com.im.service.dto.FileUpload;
import com.im.service.dto.ImplementProject;
import com.im.service.dto.PageQuery;
import com.im.service.dto.PlanDeclareSet;
import com.im.service.dto.PlanProject;
import com.im.service.dto.ProjProceSubmit;
import com.im.service.dto.ProjectStage;
import com.im.service.dto.StageNode;
import com.im.service.projectInfo.smo.IProjectInfoOperSMO;
import com.im.service.projectInfo.smo.IProjectInfoQuerySMO;
import com.im.util.DateUtil;
import com.im.util.ExcelUtil;
import com.im.util.JsonUtil;
import com.im.util.ReturnsUtil;
import com.im.util.StringUtil;
import com.im.viewmodel.projectInfo.ProjProceSubmitListRespVo;
import com.im.viewmodel.projectInfo.ProjectSetProgressAddReqVo;

import net.sf.json.JSONObject;

/** 
 * 项目信息管理后端服务. 

 * @author xuwb
 * 2018年3月21日
 */
@RestController
@RequestMapping("/projectInfoService")
public class ProjectInfoService {

	private static final Logger logger = LogManager.getLogger(ProjectInfoService.class);

	@Autowired
	private IProjectInfoOperSMO projectInfoOperSMO;
	
	@Autowired
	private IProjectInfoQuerySMO projectInfoQuerySMO;
	
	@Autowired
	private IFileQueryDAO fileQueryDAO;
	
	
	/**
	 * 
	 * 规划工程列表查询. 
	 * 
	 * @param jsonStr
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryPlanProjList")
	public String queryPlanProjList(@RequestBody String jsonStr){
		if (logger.isInfoEnabled()) {
			logger.info("请求入参json:{}", jsonStr);
		}
		
		try {
			if (jsonStr == null || jsonStr.length() <= 0) {
				throw new BaseException("请求入参为空，请核查数据!");
			}
			
			PageQuery<PlanProject> result = projectInfoQuerySMO.queryPlanProjList(jsonStr);
			
			return ReturnsUtil.returnSuccess(result).toString();
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			return ReturnsUtil.returnFailure(e.getMessage());
		}
	}
	
	/**
	 * 
	 * 规划工程信息 导出
	 * 未启用
	 * @param jsonStr
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/exportPlanProjList")
	public void exportPlanProjList(String json,HttpServletResponse response){
		if (logger.isInfoEnabled()) {
			logger.info("请求入参:{}", json);
		}
//		String json = request.getParameter("json");
		JSONObject jsonObject = JSONObject.fromObject(json);
		String jsonStr = JsonUtil.getNotNullStringFromJSON(jsonObject, "param", "获取入参时：");
		if (logger.isInfoEnabled()) {
			logger.info("请求入参json:{}", jsonStr);
		}
		
		try {
			PageQuery<PlanProject> result = projectInfoQuerySMO.queryPlanProjList(jsonStr);
			List<PlanProject> list = result.getRows();
			
			HSSFWorkbook workbook = ExcelUtil.obtianPlanProjWorkbook(list);
	        String filename = "工程信息"+DateUtil.getNowDefault()+".xls";

	        //浏览器下载excel
	        ExcelUtil.downloadExcelFile(filename, workbook, response);
			
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
		}
	}
    
	/**
	 *
	 * 规划工程列表查询.
	 *
	 * @param jsonStr
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryAllPlanProjList")
	public String queryAllPlanProjList(@RequestBody String jsonStr){
		if (logger.isInfoEnabled()) {
			logger.info("请求入参json:{}", jsonStr);
		}

		try {
			if (jsonStr == null || jsonStr.length() <= 0) {
				throw new BaseException("请求入参为空，请核查数据!");
			}

			List<PlanProject> result = projectInfoQuerySMO.queryAllPlanProjList(jsonStr);

			return ReturnsUtil.returnSuccess(result).toString();
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			return ReturnsUtil.returnFailure(e.getMessage());
		}
	}

	/**
	 *
	 *  新增规划工程信息
	 * @param  入参
	 * @return
	 * @throws Exception
	 */
	@PostMapping(value = "/addPlanProj")
	public String addPlanProject(@RequestBody String jsonStr){
		if (logger.isInfoEnabled()) {
			logger.info("请求入参:{}", jsonStr);
		}
		try {
			PlanProject planProject = JsonUtil.jsonToBean(jsonStr, PlanProject.class);
			if (planProject == null) {
				throw new BaseException("请求入参为空，请核查数据!");
			}
			projectInfoOperSMO.addPlanProject(planProject);
			return ReturnsUtil.returnSuccess(new JSONObject()).toString();
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			return ReturnsUtil.returnFailure(e.getMessage());
		}
	}
	
	/**
	 * 
	 * 查询规划工程详情. 
	 * 
	 * @param
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryPlanProjDetail")
	public String queryPlanProjDetail(@RequestBody String jsonStr){
		if (logger.isInfoEnabled()) {
			logger.info("请求入参:{}", jsonStr);
		}
		
		try {
			PlanProject planProj = JsonUtil.jsonToBean(jsonStr, PlanProject.class);
			
			if (planProj == null || StringUtil.isEmpty(planProj.getPlanProjId())) {
				throw new BaseException("请求入参为空，请核查数据!");
			}
			
			PlanProject result = projectInfoQuerySMO.queryPlanProjDetail(planProj);
			
			return ReturnsUtil.returnSuccess(result).toString();
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			return ReturnsUtil.returnFailure(e.getMessage());
		}
	}
	
	/**
	 *
	 *  修改规划工程信息
	 * @param planProject 入参
	 * @return
	 * @throws Exception
	 */
	@PostMapping(value = "/updatePlanProj")
	public String updatePlanProject(@RequestBody String jsonStr){
		if (logger.isInfoEnabled()) {
			logger.info("请求入参:{}", jsonStr);
		}
		try {
			PlanProject planProject = JsonUtil.jsonToBean(jsonStr, PlanProject.class);
			
			if (planProject == null || StringUtil.isEmpty(planProject.getPlanProjId())) {
				return ReturnsUtil.returnFailure("请求入参为空，请核查数据!");
			}
			projectInfoOperSMO.updatePlanProject(planProject);
			
			return ReturnsUtil.returnSuccess(new JSONObject()).toString();
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			return ReturnsUtil.returnFailure(e.getMessage());
		}
	}
	
	/**
	 *
	 *  修改规划工程信息
	 *  支持批量删除
	 * @param planProject 入参
	 * @return
	 * @throws Exception
	 */
	@PostMapping(value = "/deletePlanProj")
	public String deletePlanProj(@RequestBody PlanProject planProject){
		if (logger.isInfoEnabled()) {
			logger.info("请求入参:{}", planProject.toString());
		}
		try {
			if (planProject == null || (StringUtil.isEmpty(planProject.getPlanProjId())
					&& StringUtil.isEmpty(planProject.getPlanProjIds()))) {
				return ReturnsUtil.returnFailure("请求入参为空，请核查数据!");
			}
			projectInfoOperSMO.deletePlanProj(planProject);
			
			return ReturnsUtil.returnSuccess(new JSONObject()).toString();
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			return ReturnsUtil.returnFailure(e.getMessage());
		}
	}
	
	/**
	 * 
	 * 规划工程分类查询
	 * @param
	 * @return 
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryPlanProjClassConstList")
	public String queryPlanProjClassConstList(){
		try {
			String constCode = "PLAN_PROJ_CLASS";//常量编码-工程规划分类
			List<BusiConstParamVal> result = projectInfoQuerySMO.queryConstListByCode(constCode);
			
			return ReturnsUtil.returnSuccess(result).toString();
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			return ReturnsUtil.returnFailure(e.getMessage());
		}
	}
	
	
	/**
	 *
	 *  新增实施工程信息
	 * @param  入参
	 * @return
	 * @throws Exception
	 */
	@PostMapping(value = "/addImpleProj")
	public String addImpleProj(@Valid@RequestBody ImplementProject implProj,BindingResult bindingResult){
		if (logger.isInfoEnabled()) {
			logger.info("请求入参:{}", implProj.toString());
		}
		try {
//			if (implProj == null) {
//				throw new BaseException("请求入参为空，请核查数据!");
//			}
			if (bindingResult.hasErrors()){
				return ReturnsUtil.returnFailure(bindingResult.getFieldError().getDefaultMessage());
		    }
			projectInfoOperSMO.addImplementProj(implProj);
			return ReturnsUtil.returnSuccess(new JSONObject()).toString();
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			return ReturnsUtil.returnFailure(e.getMessage());
		}
	}
	
	/**
	 * 
	 * 实施工程列表查询. 
	 * 
	 * @param jsonStr
	 * @return 
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryImpleProjList")
	public String queryImpleProjList(@RequestBody String jsonStr){
		if (logger.isInfoEnabled()) {
			logger.info("请求入参json:{}", jsonStr);
		}
		
		try {
			if (jsonStr == null || jsonStr.length() <= 0) {
				throw new BaseException("请求入参为空，请核查数据!");
			}
			
			PageQuery<ImplementProject> result = projectInfoQuerySMO.queryImpleProjList(jsonStr);
			
			return ReturnsUtil.returnSuccess(result).toString();
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			return ReturnsUtil.returnFailure(e.getMessage());
		}
	}

	/**
	 *
	 * 实施工程列表查询.
	 *
	 * @param jsonStr
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryAllImpleProjList")
	public String queryAllImpleProjList(@RequestBody String jsonStr){
		if (logger.isInfoEnabled()) {
			logger.info("请求入参json:{}", jsonStr);
		}

		try {
			if (jsonStr == null || jsonStr.length() <= 0) {
				throw new BaseException("请求入参为空，请核查数据!");
			}

			List<ImplementProject> result = projectInfoQuerySMO.queryAllImpleProjList(jsonStr);

			return ReturnsUtil.returnSuccess(result).toString();
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			return ReturnsUtil.returnFailure(e.getMessage());
		}
	}
	
	/**
	 *
	 *  修改实施工程信息
	 * @param implProj 入参
	 * @return
	 * @throws Exception
	 */
	@PostMapping(value = "/updateImpleProj")
	public String updateImpleProj(@RequestBody ImplementProject implProj){
		if (logger.isInfoEnabled()) {
			logger.info("请求入参:{}", implProj.toString());
		}
		try {
			if (implProj == null || StringUtil.isEmpty(implProj.getImpleProjId())) {
				throw new BaseException("请求入参为空，请核查数据!");
			}
			projectInfoOperSMO.updateImpleProj(implProj);
			
			return ReturnsUtil.returnSuccess(new JSONObject()).toString();
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			return ReturnsUtil.returnFailure(e.getMessage());
		}
	}
	
	/**
	 *
	 *  删除实施工程信息
	 * @param implProj 入参
	 * @return
	 * @throws Exception
	 */
	@PostMapping(value = "/deleteImpleProj")
	public String deleteImpleProj(@RequestBody ImplementProject implProj){
		if (logger.isInfoEnabled()) {
			logger.info("请求入参:{}", implProj.toString());
		}
		try {
			if (implProj == null || (StringUtil.isEmpty(implProj.getImpleProjId())
					&& StringUtil.isEmpty(implProj.getImpleProjIds()))) {
				return ReturnsUtil.returnFailure("请求入参为空，请核查数据!");
			}
			
			projectInfoOperSMO.deleteImpleProj(implProj);
			
			return ReturnsUtil.returnSuccess(new JSONObject()).toString();
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			return ReturnsUtil.returnFailure(e.getMessage());
		}
	}
	
	/**
	 * 
	 * 查询实施项目详情. 
	 * 
	 * @param
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryImpleProjDetail")
	public String queryImpleProjDetail(@RequestBody ImplementProject implProj){
		if (logger.isInfoEnabled()) {
			logger.info("请求入参:{}", implProj.toString());
		}
		
		try {
			if (implProj == null || StringUtil.isEmpty(implProj.getImpleProjId())) {
				throw new BaseException("请求入参为空，请核查数据!");
			}
			
			ImplementProject result = projectInfoQuerySMO.queryImpleProjDetail(implProj);
			
			return ReturnsUtil.returnSuccess(result).toString();
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			return ReturnsUtil.returnFailure(e.getMessage());
		}
	}
	
	/**
	 * 
	 * 项目阶段常量信息查询. 
	 * 全量的项目阶段
	 * @param
	 * @return 
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryProjStageConstList")
	@Deprecated
	public String queryProjStageConstList(){
		try {
			String constCode = "PRE_WORK_APPROVALl";//常量编码-项目阶段
			List<BusiConstParamVal> result = projectInfoQuerySMO.queryConstListByCode(constCode);
			
			PageQuery<BusiConstParamVal> pageResult = new PageQuery<BusiConstParamVal>();
			pageResult.setRows(result);
			
			return ReturnsUtil.returnSuccess(pageResult).toString();
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			return ReturnsUtil.returnFailure(e.getMessage());
		}
	}
	
	/**
	 * 查询实施项目设置的所需经历的阶段信息
	 * 包含全量的项目阶段
	 * 将 queryProjStageConstList 合入此方法方便前端调用
	 * @param projStage
	 * @return
	 */
	@RequestMapping(value = "/queryImpleProjStageList")
	public String queryImpleProjStageList(@RequestBody String jsonStr){
		if (logger.isInfoEnabled()) {
			logger.info("请求入参:{}", jsonStr);
		}
		try {
			ProjectStage projStage = JsonUtil.jsonToBean(jsonStr, ProjectStage.class);
			
			if (projStage == null || StringUtil.isEmpty(projStage.getImpleProjId())) {
				return ReturnsUtil.returnFailure("请求入参项目id为空，请核查数据!");
			}
			// 1.查询全量的项目阶段
			String constCode = "PRE_WORK_APPROVALl";//常量编码-项目阶段
			List<BusiConstParamVal> constResult = projectInfoQuerySMO.queryConstListByCode(constCode);
			
			// 2.查询项目已设置的阶段信息
			List<ProjectStage> projStageList = projectInfoQuerySMO.queryImpleProjStageList(projStage);
			
			// 3.合并全量阶段与项目已设置阶段信息
			List<ProjectStage> result = new ArrayList<ProjectStage>();
			for(BusiConstParamVal bcp : constResult){
				ProjectStage resultObj = new ProjectStage();
				resultObj.setImpleProjId(projStage.getImpleProjId());
				resultObj.setProjStageClass(bcp.getParamValValue());
				resultObj.setProjStateName(bcp.getParamValName());
				
				for(ProjectStage temp : projStageList){
					if(temp.getProjStageClass().equals(bcp.getParamValValue())){
						resultObj = temp;
						resultObj.setImpleProjId(projStage.getImpleProjId());
					}
				}
				result.add(resultObj);
			}
			
			// 4.项目已设置阶段关联附件
			 for(ProjectStage temp : result){
				 String projStageId = temp.getProjStageId();
				if(!StringUtil.isEmpty(projStageId)){
					Map<String,Object> param = new HashMap<String,Object>();
					param.put("uploadObjId",projStageId);
					List<FileUpload> fileUploadList = fileQueryDAO.queryFileUploadsByCond(param);
					if(fileUploadList != null && fileUploadList.size() > 0){
						StringBuffer sb =  new StringBuffer();
						for(FileUpload fu : fileUploadList){
							sb.append(";").append(fu.getUploadName());
						}
						temp.setUploadName(sb.substring(1));
						
						temp.setFileList(fileUploadList);
					}
				}
			}
			
			// 5.包装rows返回前端
			PageQuery<ProjectStage> pageResult = new PageQuery<ProjectStage>();
			pageResult.setRows(result);
			
			return ReturnsUtil.returnSuccess(pageResult).toString();
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			return ReturnsUtil.returnFailure(e.getMessage());
		}
	}
	
	/**
	 *
	 *  新增工程阶段信息
	 * @param
	 * @return
	 * @throws Exception
	 */
	@PostMapping(value = "/addProjStage")
	public String addProjStage(@Valid@RequestBody ProjectStage projStage,BindingResult bindingResult){
		if (logger.isInfoEnabled()) {
			logger.info("请求入参:{}", projStage.toString());
		}
		try {
			if (bindingResult.hasErrors()){
				return ReturnsUtil.returnFailure(bindingResult.getFieldError().getDefaultMessage());
		    }
			projectInfoOperSMO.addProjStage(projStage);
			return ReturnsUtil.returnSuccess(new JSONObject()).toString();
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			return ReturnsUtil.returnFailure(e.getMessage());
		}
	}
	
	/**
	 *
	 *  新增工程阶段信息
	 * @param
	 * @return
	 * @throws Exception
	 */
	@PostMapping(value = "/uploadProjStageFile")
	public String uploadProjStageFile(@RequestBody ProjectStage projStage){
		if (logger.isInfoEnabled()) {
			logger.info("请求入参:{}", projStage.toString());
		}
		try {
			if (projStage == null || StringUtil.isEmpty(projStage.getProjStageId())) {
				return ReturnsUtil.returnFailure("请求入参阶段id为空，请核查数据!");
			}
			projectInfoOperSMO.uploadProjStageFile(projStage);
			return ReturnsUtil.returnSuccess(new JSONObject()).toString();
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			return ReturnsUtil.returnFailure(e.getMessage());
		}
	}
	
	/**
	 *
	 *  更新工程阶段信息
	 * @param
	 * @return
	 * @throws Exception
	 */
	@PostMapping(value = "/updateProjStage")
	public String updateProjStage(@Valid@RequestBody ProjectStage projStage,BindingResult bindingResult){
		if (logger.isInfoEnabled()) {
			logger.info("请求入参:{}", projStage.toString());
		}
		try {
			if (bindingResult.hasErrors()){
				return ReturnsUtil.returnFailure(bindingResult.getFieldError().getDefaultMessage());
		    }
			projectInfoOperSMO.updateProjStage(projStage);
			return ReturnsUtil.returnSuccess(new JSONObject()).toString();
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			return ReturnsUtil.returnFailure(e.getMessage());
		}
	}
	
	/**
	 *
	 *  更新工程阶段信息
	 * @param
	 * @return
	 * @throws Exception
	 */
	@PostMapping(value = "/deleteProjStage")
	public String deleteProjStage(@RequestBody ProjectStage projStage){
		if (logger.isInfoEnabled()) {
			logger.info("请求入参:{}", projStage.toString());
		}
		try {
			if (projStage == null || StringUtil.isEmpty(projStage.getProjStageId())
					|| StringUtil.isEmpty(projStage.getImpleProjId()) || StringUtil.isEmpty(projStage.getProjStageClass())) {
				return ReturnsUtil.returnFailure("请求入参为空，请核查数据!");
			}
			projStage.setStatusCd(MDA.PROJECT_STAGE_STATUS_CD_DELETE);
			projectInfoOperSMO.updateProjStage(projStage);
			return ReturnsUtil.returnSuccess(new JSONObject()).toString();
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			return ReturnsUtil.returnFailure(e.getMessage());
		}
	}
	
	/**
	 * 
	 * 填报项目进度设定---列表查询 
	 * 因设计变 调整为 只查询出 实施项目 信息
	 * @param jsonStr
	 * @return 
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryImpleDeclareSetList")
	public String queryImpleDeclareSetList(@RequestBody String jsonStr){
		if (logger.isInfoEnabled()) {
			logger.info("请求入参json:{}", jsonStr);
		}
		
		try {
			if (jsonStr == null || jsonStr.length() <= 0) {
				throw new BaseException("请求入参为空，请核查数据!");
			}
			
			PageQuery<ImplementProject> result = projectInfoQuerySMO.queryImpleDeclareSetList(jsonStr);
			
			return ReturnsUtil.returnSuccess(result).toString();
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			return ReturnsUtil.returnFailure(e.getMessage());
		}
	}
	
	/**
	 *
	 *  填报项目进度设定---修改  
	 *  支持批量操作
	 * @param
	 * @return
	 * @throws Exception
	 */
	@PostMapping(value = "/updateProjPlanDeclareSet")
	public String updateProjPlanDeclareSet(@Valid@RequestBody ProjectSetProgressAddReqVo addReqVo,BindingResult bindingResult){
		if (logger.isInfoEnabled()) {
			logger.info("请求入参:{}", addReqVo.toString());
		}
		try {
			if (bindingResult.hasErrors()){
				return ReturnsUtil.returnFailure(bindingResult.getFieldError().getDefaultMessage());
		    }
			projectInfoOperSMO.updateProjPlanDeclareSet(addReqVo);
			return ReturnsUtil.returnSuccess(new JSONObject()).toString();
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			return ReturnsUtil.returnFailure(e.getMessage());
		}
	}
	
	/**
	 *
	 *  填报项目进度设定---删除
	 *  
	 *  设计变更该功能 不需要了
	 * @param planProject 入参
	 * @return
	 * @throws Exception
	 */
	@PostMapping(value = "/deleteProjPlanDeclareSet")
	@Deprecated
	public String deleteProjPlanDeclareSet(@RequestBody PlanDeclareSet planDs){
		if (logger.isInfoEnabled()) {
			logger.info("请求入参:{}", planDs.toString());
		}
		try {
			if (planDs == null || StringUtil.isEmpty(planDs.getDeclareSetId())) {
				throw new BaseException("请求入参为空，请核查数据!");
			}
			projectInfoOperSMO.deleteProjPlanDeclareSet(planDs);
			
			return ReturnsUtil.returnSuccess(new JSONObject()).toString();
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			return ReturnsUtil.returnFailure(e.getMessage());
		}
	}
	
	/**
	 * 
	 * 项目进度报送---列表查询 
	 * 项目进度报送统计 --列表查询
	 * @param jsonStr
	 * @return 
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryProjProceSubmitList")
	public String queryProjProceSubmitList(@RequestBody String jsonStr){
		if (logger.isInfoEnabled()) {
			logger.info("请求入参json:{}", jsonStr);
		}
		
		try {
			if (jsonStr == null || jsonStr.length() <= 0) {
				throw new BaseException("请求入参为空，请核查数据!");
			}
			PageQuery<ProjProceSubmitListRespVo> result = projectInfoQuerySMO.queryProjProceSubmitList(jsonStr);
			
			return ReturnsUtil.returnSuccess(result).toString();
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			return ReturnsUtil.returnFailure(e.getMessage());
		}
	}
	
	
	/**
	 *
	 *  项目进度报送---修改
	 * @param planProject 入参
	 * @return
	 * @throws Exception
	 */
	@PostMapping(value = "/updateProjProceSubmit")
	public String updateProjProceSubmit(@RequestBody ProjProceSubmit projProceSubmit,HttpServletRequest request){
		if (logger.isInfoEnabled()) {
			logger.info("请求入参:{}", projProceSubmit.toString());
		}
		try {
			if (projProceSubmit == null || StringUtil.isEmpty(projProceSubmit.getImpleProjId())) {
				throw new BaseException("请求入参为空，请核查数据!");
			}
			projectInfoOperSMO.updateProjProceSubmit(projProceSubmit,request);
			
			return ReturnsUtil.returnSuccess(new JSONObject()).toString();
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			return ReturnsUtil.returnFailure(e.getMessage());
		}
	}
	//---------------------------文档信息
	/**
	 *
	 *  新增项目节点信息
	 * @param  入参
	 * @return 
	 * @throws Exception
	 */
	@PostMapping(value = "/addStageNode")
	public String addStageNode(@Valid@RequestBody StageNode stageNode,BindingResult bindingResult){
		if (logger.isInfoEnabled()) {
			logger.info("请求入参:{}", stageNode.toString());
		}
		try {
			if (bindingResult.hasErrors()){
				return ReturnsUtil.returnFailure(bindingResult.getFieldError().getDefaultMessage());
		    }
			projectInfoOperSMO.addStageNode(stageNode);
			return ReturnsUtil.returnSuccess(new JSONObject()).toString();
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			return ReturnsUtil.returnFailure(e.getMessage());
		}
	}
	
	/**
	 *
	 *  新增文档信息
	 * @param  入参
	 * @return 
	 * @throws Exception
	 */
	@PostMapping(value = "/addDocInfo")
	public String addDocInfo(HttpServletRequest request,@Valid@RequestBody DocInfo docInfo,BindingResult bindingResult){
		if (logger.isInfoEnabled()) {
			logger.info("请求入参:{}", docInfo.toString());
		}
		try {
			if (bindingResult.hasErrors()){
				return ReturnsUtil.returnFailure(bindingResult.getFieldError().getDefaultMessage());
		    }
			projectInfoOperSMO.addDocInfo(docInfo,request);
			return ReturnsUtil.returnSuccess(new JSONObject()).toString();
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			return ReturnsUtil.returnFailure(e.getMessage());
		}
	}
	
}
